package com.fable.sp.core.domain;

import com.fable.sp.core.util.JSONType;
import org.hibernate.annotations.Type;
import org.springframework.util.StringUtils;

import javax.persistence.*;

/**
 * .
 *
 * @author stormning on 16/7/30.
 */
@Entity
@Table(name = "sp_layout", indexes = {@Index(columnList = "container_id"), @Index(columnList = "original")})
public class Layout extends StyleEntity {

    @Column(name = "container_id")
    private long containerId;

    @Column(name = "name")
    private String name;

    @Column(name = "info")
    private String info;

    @Column(name = "cell_height")
    private Integer cellHeight = 50;

    @Column(length = 1500)
    @Type(type = JSONType.TYPE)
    private Border cellBorder = Border.DEFAULT;

    @Column(name = "cell_padding", length = 1500)
    @Type(type = JSONType.TYPE)
    private Box cellPadding;

    @Column(name = "cell_margin", length = 1500)
    @Type(type = JSONType.TYPE)
    private Box cellMargin;

    @Column(name = "original")
    private boolean original = false;

    @Column(name = "condition0")
    private String condition;

    @Transient
    private Long copyId;

    @Transient
    private int height;

    @Transient
    private String mode;

    @Transient
    private String rendered;

    public long getContainerId() {
        return containerId;
    }

    public void setContainerId(long containerId) {
        this.containerId = containerId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCondition() {
        return condition;
    }

    public void setCondition(String condition) {
        this.condition = condition;
        if (StringUtils.hasText(condition)) {
            setOriginal(false);
        }
    }

    public boolean isOriginal() {
        return original;
    }

    public void setOriginal(boolean original) {
        this.original = original;
    }

    public Integer getCellHeight() {
        return (cellHeight == null || cellHeight <= 0) ? 50 : cellHeight;
    }

    public void setCellHeight(Integer cellHeight) {
        this.cellHeight = cellHeight;
    }

    public String getInfo() {
        return info;
    }

    public void setInfo(String info) {
        this.info = info;
    }

    public Long getCopyId() {
        return copyId;
    }

    public void setCopyId(Long copyId) {
        this.copyId = copyId;
    }

    public Border getCellBorder() {
        return cellBorder;
    }

    public void setCellBorder(Border cellBorder) {
        this.cellBorder = cellBorder;
    }

    public Box getCellPadding() {
        return cellPadding;
    }

    public void setCellPadding(Box cellPadding) {
        this.cellPadding = cellPadding;
    }

    public Box getCellMargin() {
        return cellMargin;
    }

    public void setCellMargin(Box cellMargin) {
        this.cellMargin = cellMargin;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public String getMode() {
        return mode;
    }

    public void setMode(String mode) {
        this.mode = mode;
    }

    public String getRendered() {
        return rendered;
    }

    public void setRendered(String rendered) {
        this.rendered = rendered;
    }
}
